package com.colourclash.fruitopia.particles 
{
	import com.colourclash.fruitopia.resources.EmbeddedAssets;
	import com.colourclash.fruitopia.utils.Global;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import idv.cjcat.display.particles.AddChildMode;
	import idv.cjcat.display.particles.LineGravity;
	import idv.cjcat.display.particles.PointEmitter;
	import idv.cjcat.geom.Vector2;
	/**
	 * Star-burst particles for when a fruit is destroyed
	 * 
	 * @author Patrick Hammond
	 */
	public class StarParticles extends Sprite implements IParticleEffect
	{
		private var _emmiter:PointEmitter;
		
		public function StarParticles(position:Point) 
		{
			_emmiter = new PointEmitter(StarParticle, parent);
			_emmiter.x = position.x + 30 * Global.getInstance().getScale();
			_emmiter.y = position.y + 30 * Global.getInstance().getScale();
		
			_emmiter.setConfig(
				{rate:1, rateVar:2, life:10, lifeVar:5, speed:5, speedVar:15, direction:new Vector2(0, -1), directionVar:30, bidirectional:false, oriented:false, gravities:[new LineGravity(0, 0.3)], initAngle:0, initAngleVar:360, spin:5, spinVar:15, initAlpha:1, initAlphaVar:0, finalAlpha:0, finalAlphaVar:0, scale:0.1, scaleVar:.5, finalScale:.5, finalScaleVar:0, alphaDecayAt:5, alphaDecayAtVar:0, scaleDecayAt:5, scaleDecayAtVar:0, addChildMode:AddChildMode.RANDOM, bubbleMotion:false, bubbleAmplitude:20, bubbleAmplitudeVar:5, bubbleFrequency:0.2, bubbleFrequencyVar:0.5}
			);
			_emmiter.start();
			addChild(_emmiter);
			addEventListener(Event.ENTER_FRAME, _emmiter.step, false, 0, true);
		}
		
		/* INTERFACE com.colourclash.fruitopia.particles.IParticleEffect */
		
		public function stop():void 
		{
			_emmiter.stop();
		}
		
		public function destroy():void 
		{
			removeEventListener(Event.ENTER_FRAME, _emmiter.step);
			removeChild(_emmiter);
			parent.removeChild(this);
		}
		
	}

}